package com.qf.BaseController;

import com.qf.dao.UserDaoImpl;
import com.qf.pojo.User;
import com.qf.service.AdminServiceImpl;
import com.sun.org.glassfish.gmbal.Description;

import javax.jws.WebService;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.WebEndpoint;



@WebServlet("/admin")
public class AdminController  extends BaseServlet{
      public  String login(HttpServletRequest request, HttpServletResponse response){
          String username = request.getParameter("username");
          String password = request.getParameter("password");

          if(username==null || password==null){
              return  "redirect:"+request.getContextPath()+"/admin/login.jsp";
          }
          //3. 调用service校验用户名密码
          AdminServiceImpl adminService = new AdminServiceImpl(new UserDaoImpl());
          User user = adminService.login(username, password);

          //4. 根据结果判断进行重定向操作
          if(user!=null){
              //5. 将登录成功后的用户对象放入tomcat的session会话中一直携带
              request.getSession().setAttribute("admin",user);
              return "redirect:"+request.getContextPath()+"/admin/admin.jsp";



          }else{
              //用户名, 密码不正确, 跳转到登录页面重新登录
              return  "redirect:"+request.getContextPath()+"/admin/login.jsp";
          }

      }



}
